package objects;

import graphics.*;

import java.awt.Color;
import java.awt.Shape;
import java.awt.geom.Ellipse2D;

import animation.Explosion;

import main.Constants;
import main.Game;

import util.*;
import weapons.Shot;
import ship.*;
import structure.*;

public class Asteroid extends SObject implements Damaging {
	private int xRad, yRad;
	private static final int MAX_X = 5;

	public Asteroid(Point p) {
		super(p);
		xRad = (int) (Math.random() * MAX_X)  + 1;
		yRad = (int) (Math.random() * MAX_X)  + 1;

	}

	public Asteroid(Point p, int xRad, int yRad) {
		super(p);
		this.xRad = xRad;
		this.yRad = yRad;

	}

	@Override
	public double getMass() {
		// TODO Auto-generated method stub
		return 1;
	}

	public int xRad() {
		return xRad;
	}
	public int yRad() {
		return yRad;
	}

	@Override
	public double getRadius() {
		// TODO Auto-generated method stub
		return Math.max(xRad, yRad);
	}

	@Override
	public void draw(MaxGraphics g) {
		Drawing.drawAsteroid(g, cords, new Point(xRad, yRad));
	}

	public Shape[] getShape() {
		Shape[] s = { new Ellipse2D.Double(getX() - xRad, getY() - yRad, (double) xRad * 2, (double) yRad * 2) };
		return s;
	}

	@Override
	public void collide(SObject o) {
		if(o instanceof Ship || o instanceof Shot) {
			flag();
		}
		if(o instanceof Shot) {
			Game.game.registerObject(new Explosion(this.getCords(), ((Shot) o).getVel(), 10, 15), Constants.COLLIDE |
					Constants.DRAW | Constants.MOVE);

		}
	}


	public double getDamage() {
		// TODO Auto-generated method stub
		return .1;
	}

	@Override
	public String toString() {
		return "Asteroid " + getX() + " " + getY() + " " + xRad + " " + yRad;
	}

}
